package com.wisdytech.common.bean;

import com.github.pagehelper.Page;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * 
 * <p>ClassName: BasePageInfo</p>
 * <p>Description: 基本的分页信息</p>
 * <p>Author: dailibo</p>
 * <p>Date: 2017-9-30</p>
 */
public class  BasePageInfo<T> implements Serializable{

    /**
     * <p>Field serialVersionUID: TODO</p>
     */
    private static final long serialVersionUID = -7850989012460943040L;
    
    //当前页
    private int pageNum;
    //每页的数量
    private int pageSize;
    
    //总记录数
    private long total;
    //总页数
    private int pages;
    
    //结果集
    private List<T> list;
    
    public BasePageInfo(){
        super();
    }
    
    public BasePageInfo(List<T> list){
        this.list=list;

        if (list instanceof Page) {
            Page page = (Page) list;
            this.pageNum = page.getPageNum();
            this.pageSize = page.getPageSize();

            this.pages = page.getPages();
            this.list = page;
            
            this.total = page.getTotal();
            
        } else if (list instanceof Collection) {
            this.pageNum = 1;
            this.pageSize = list.size();

            this.pages = this.pageSize > 0 ? 1 : 0;
            this.list = list;
            this.total = list.size();
        }
        
    
    }
    
    
    
    public int getPageNum() {
        return pageNum;
    }
    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    public long getTotal() {
        return total;
    }
    public void setTotal(long total) {
        this.total = total;
    }
    public int getPages() {
        return pages;
    }
    public void setPages(int pages) {
        this.pages = pages;
    }
    public List getList() {
        return list;
    }
    public void setList(List list) {
        this.list = list;
    }
    
    

}
